<?php
/**
 * Created by PhpStorm.
 * User: xpz
 * Date: 2021/5/11
 * Time: 12:46
 */

namespace fast;

use fast\Encrypt;
use app\common\library\Wxtoken;
use think\config;

class Tool
{
    /**
     * 获取当前页面网址
     */
    public static function get_url()
    {
        $sys_protocal = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://';
        $php_self = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
        $path_info = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '';
        //$relate_url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $php_self . (isset($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : $path_info);
        return $sys_protocal . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '');
    }


    public static function expression($content, $filename = '')
    {
        //正则匹配图片  ?(.*?)[\"|\']?\s.*?
        $pattern = '/(.*).(gif|jpg|jpeg|bmp|png)/is';
        preg_match_all($pattern, $content, $matches);
        if (isset($matches[0])) {
            foreach ($matches[0] as $k => $v) {
                $url = '<img  onclick="getimg(this)" src="' . $v . '" class="picture" />';
                $content = str_replace($matches[0][$k], $url, $content);
            }
        }
        //正则匹配文件  /uploads/20190221/4a32c984dd2832f5524f5c958b10c97a.zip
        $pattern = '/(.*).(doc$|docx|xls$|xlsx|zip|rar|pdf)/is';
        preg_match_all($pattern, $content, $matches);
        if (isset($matches[0][0])) {
            if (!$filename) {
                $file_name = explode('/', $matches[0][0]);
                $filename = $file_name[3];
            }
            foreach ($matches[0] as $k => $v) {
                $url = '<div class="customer"><pre><a class="attach-exp" href="' . $v . '" style="display: inline-block;text-align: center;min-width: 70px;text-decoration: none;" download="' . $filename . '"><i class="layui-icon" style="font-size: 60px;"></i><br>' . $filename . '</a></pre></div>';
                $content = str_replace($matches[0][$k], $url, $content);
            }
        }
        //正则匹配表情
        #$pattern = '/:(\w+):/'; //这个会匹配到数组 :29:
        $pattern = '/:([a-z_]*?):/';
        preg_match_all($pattern, $content, $match);
        if (isset($match[1])) {
            $img = '';
            foreach ($match[1] as $k => $v) {
                $img = '<img src="/assets/addons/onlineservice/img/smilies/' . $v . '.png" alt="" class="wp-smiley" style="height: 1.5em;max-height:1.5em;">';
                $content = str_replace($match[0][$k], $img, $content);
            }
        }
        return $content;
    }

    public static function get_uuid()
    {
        if (function_exists('com_create_guid')) {
            return com_create_guid();
        } else {
            mt_srand((double)microtime() * 10000);//optional for php 4.2.0 and up.
            $charid = strtoupper(md5(uniqid(rand(), true)));
            $hyphen = chr(45);// " - "
            $uuid = substr($charid, 0, 8) . $hyphen
                . substr($charid, 8, 4) . $hyphen
                . substr($charid, 12, 4) . $hyphen
                . substr($charid, 16, 4) . $hyphen
                . substr($charid, 20, 12);// "}"
            return $uuid;
        }
    }

    public static function getTaobaoArea($ip)
    {
//        $url = 'http://ip.taobao.com/service/getIpInfo.php?ip=' . $ip;
        $url = 'https://restapi.amap.com/v3/ip?key=' . Config::get('xpz.amap_key') . '&ip=' . $ip;
        $content = self::curl($url);
        $content = json_decode($content);
        if (isset($content) && $content->status == 1) {
            $arr['country'] = '';
            $arr['province'] = $content->province;
            $arr['city'] = $content->city;
            return $arr;
        }
    }


    public static function wxLineNotice($touser, $content)
    {
        return 'ok';
        $url = $touser . '/' . $content;
        $rs = self::curl($url);
        return $rs;
//        if($rs == 'ok'){
//            echo "成功！";
//        } else {
//            echo "失败！";
//        }
    }

    /**
     * 试用申请被拒绝微信通知
     * @param type $touser
     * @param type $name
     * @return string
     */
    public static function approvedNoNotice($touser, $name)
    {
        if (empty($touser)) {
            echo "touser不能为空！";
            exit;
        }
        if (empty($name)) {
            echo "name不能为空！";
            exit;
        }

//        $tourl = Tool::getDomain().'/visitorgetcode/'.$token;
        $data = '{
           "touser":"' . $touser . '",
           "template_id":"' . Config::get('xpz.wx_message_template_id_1') . '",
           "url":"",        
           "data":{
                   "first": {
                       "value":"主人，有客户留言啦",
                       "color":"#173177"
                   },
                   "keyword1":{
                       "value":"试用申请被拒绝，请联系工作人员！",
                       "color":"#173177"
                   },
                   "keyword2": {
                       "value":"' . $name . '",
                       "color":"#173177"
                   },
                   "keyword3": {
                       "value":"' . Config::get('xpz.kf_name') . '试用申请被拒绝！",
                       "color":"#173177"
                   },
                   "remark":{
                       "value":"感谢您的使用",
                       "color":"#173177"
                   }
           }
       }';
//        var_dump($data);
        $requestRs = Tool::send($data, "/cgi-bin/message/template/send");
//        var_dump($requestRs);
        $rs = json_decode($requestRs['body'], true);
        if ($rs['errcode'] == 0) {
            return 'ok';
        } else {
//            print_r($rs['errcode']);
//            print_r($rs['errmsg']);
            $message = "";
            if (!empty($rs)) {
                if (isset($rs['errcode'])) {
                    $message .= "errcode:" . $rs['errcode'];
                }
                if (isset($rs['errmsg'])) {
                    $message .= "=====errmsg:" . $rs['errmsg'];
                }
            }
            Tool::mylog(true, __FUNCTION__ . '给客户发送审核通过模板错误：', $data . "===" . $message, 'wx_send_tpl_error');
            return 'error';
        }
    }

    /**
     * 试用申请通过微信通知
     * @param type $touser
     * @param type $name
     * @param type $token
     * @return string
     */
    public static function approvedNotice($touser, $name, $token)
    {
        if (empty($touser)) {
            echo "touser不能为空！";
            exit;
        }
        if (empty($name)) {
            echo "name不能为空！";
            exit;
        }

        if (empty($token)) {
            echo "token不能为空！";
            exit;
        }
        $tourl = Tool::getDomain() . '/visitorgetcode/' . $token;
        $data = '{
           "touser":"' . $touser . '",
           "template_id":"' . Config::get('xpz.wx_message_template_id_1') . '",
           "url":"' . $tourl . '",        
           "data":{
                   "first": {
                       "value":"主人，有客户留言啦",
                       "color":"#173177"
                   },
                   "keyword1":{
                       "value":"试用申请审核通过",
                       "color":"#173177"
                   },
                   "keyword2": {
                       "value":"' . $name . '",
                       "color":"#173177"
                   },
                   "keyword3": {
                       "value":"' . Config::get('xpz.kf_name') . '试用，试用期一个月",
                       "color":"#173177"
                   },
                   "remark":{
                       "value":"感谢您的使用",
                       "color":"#173177"
                   }
           }
       }';
//        var_dump($data);
        $requestRs = Tool::send($data, "/cgi-bin/message/template/send");

        $rs = json_decode($requestRs['body'], true);
        if ($rs['errcode'] == 0) {
            return 'ok';
        } else {
//            print_r($rs['errcode']);
//            print_r($rs['errmsg']);
            $message = "";
            if (!empty($rs)) {
                if (isset($rs['errcode'])) {
                    $message .= "errcode:" . $rs['errcode'];
                }
                if (isset($rs['errmsg'])) {
                    $message .= "=====errmsg:" . $rs['errmsg'];
                }
            }

            Tool::mylog(true, __FUNCTION__ . '给客户发送审核通过模板错误：', $data . "===" . $message, 'wx_send_tpl_error');
            return 'error';
        }
    }

    /**
     * 给工作人员发送审核通知
     * @param type $touser
     * @param type $name
     * @param type $id
     * @param type $token
     * @return string
     */
    public static function auditUserApplyNotice($touser, $name, $id)
    {
        if (empty($touser)) {
            echo "touser不能为空！";
            exit;
        }
        if (empty($name)) {
            echo "name不能为空！";
            exit;
        }

        if (empty($id)) {
            echo "id不能为空！";
            exit;
        }


//        $tourl = Tool::getDomain().'/audituser/'.$id;
        $tourl = '';
        $data = '{
           "touser":"' . $touser . '",
           "template_id":"' . Config::get('xpz.wx_message_template_id_1') . '",
           "url":"' . $tourl . '",        
           "data":{
                   "first": {
                       "value":"主人，有客户申请试用，请您赶快处理啦",
                       "color":"#173177"
                   },
                   "keyword1":{
                       "value":"客户申请试用审核",
                       "color":"#173177"
                   },
                   "keyword2": {
                       "value":"' . $name . '",
                       "color":"#173177"
                   },
                   "keyword3": {
                       "value":"' . Config::get('xpz.kf_name') . '试用，试用期一个月",
                       "color":"#173177"
                   },
                   "remark":{
                       "value":"感谢您的使用",
                       "color":"#173177"
                   }
           }
       }';
//        var_dump($data);
        $requestRs = Tool::send($data, "/cgi-bin/message/template/send");
//        var_dump($requestRs);
        $rs = json_decode($requestRs['body'], true);
        if ($rs['errcode'] == 0) {
            return 'ok';
        } else {
//            print_r($rs['errcode']);
//            print_r($rs['errmsg']);
            $message = "";
            if (!empty($rs)) {
                if (isset($rs['errcode'])) {
                    $message .= "errcode:" . $rs['errcode'];
                }
                if (isset($rs['errmsg'])) {
                    $message .= "=====errmsg:" . $rs['errmsg'];
                }
            }
            Tool::mylog(true, __FUNCTION__ . '给工作人员发送审核试用模板错误：', $data . "===" . $message, 'wx_send_tpl_error');
            return 'error';
        }
    }

    /**
     * 网站留言微信通知
     * @param type $touser
     * @param type $id
     * @param type $name
     * @param type $content
     * @param type $token
     * @return string
     */
    public static function messageNotice($touser, $id, $name, $content, $token)
    {
        if (empty($id)) {
            echo "id不能为空！";
            exit;
        }
        if (empty($name)) {
            echo "用户不能为空！";
            exit;
        }
        if (empty($content)) {
            echo "留言内容不能为空！";
            exit;
        }
        if (empty($touser)) {
            echo "touser不能为空！";
            exit;
        }
        if (empty($content)) {
            echo "content不能为空！";
            exit;
        }

        if (empty($token)) {
            echo "token不能为空！";
            exit;
        }
        $tourl = Tool::getDomain() . '/visitorliuyan/' . $id . '/' . $token;
        $time = date('Y-m-d H:i:s', time());
        $data = '{
           "touser":"' . $touser . '",
           "template_id":"' . Config::get('xpz.wx_message_template_id_2') . '",
           "url":"' . $tourl . '",        
           "data":{
                   "first": {
                       "value":"主人，有客户留言啦",
                       "color":"#173177"
                   },
                   "user":{
                       "value":"' . $name . '",
                       "color":"#173177"
                   },
                   "ask": {
                       "value":"' . $content . '",
                       "color":"#173177"
                   },
                   "remark":{
                       "value":"' . $time . '",
                       "color":"#173177"
                   }
           }
       }';
//        var_dump($data);
        $requestRs = Tool::send($data, "/cgi-bin/message/template/send");
//        var_dump($requestRs);
        $rs = json_decode($requestRs['body'], true);
        if ($rs['errcode'] == 0) {
            return 'ok';
        } else {
//            print_r($rs['errcode']);
//            print_r($rs['errmsg']);
            $message = "";
            if (!empty($rs)) {
                if (isset($rs['errcode'])) {
                    $message .= "errcode:" . $rs['errcode'];
                }
                if (isset($rs['errmsg'])) {
                    $message .= "=====errmsg:" . $rs['errmsg'];
                }
            }
            Tool::mylog(true, __FUNCTION__ . '给客户发送留言模板错误：', $data . "===" . $message, 'wx_send_tpl_error');
            return 'error';
        }
    }

    /**
     * 微信留言通知
     * @param type $touser
     * @param type $content
     * @param type $uuid
     * @param type $token
     * @return string
     */
    public static function wxMessageNotice($touser, $content, $uuid, $token)
    {
        if (empty($touser)) {
            echo "touser不能为空！";
            exit;
        }
        if (empty($content)) {
            echo "content不能为空！";
            exit;
        }
        if (empty($uuid)) {
            echo "url不能为空！";
            exit;
        }
        if (empty($token)) {
            echo "token不能为空！";
            exit;
        }
        $tourl = Tool::getDomain() . '/kf/' . $uuid . "/" . $token;
        $time = date('Y-m-d H:i:s', time());
        $data = '{
           "touser":"' . $touser . '",
           "template_id":"' . Config::get('xpz.wx_message_template_id_3') . '",
           "url":"' . $tourl . '",        
           "data":{
                   "first": {
                       "value":"主人，有客户来咨询了！",
                       "color":"#173177"
                   },
                   "keyword1":{
                       "value":"游客",
                       "color":"#173177"
                   },
                   "keyword2": {
                       "value":"' . $time . '",
                       "color":"#173177"
                   },
                   "keyword3": {
                       "value":"' . $content . '",
                       "color":"#173177"
                   },
                   "remark":{
                       "value":"主人，来单了！",
                       "color":"#173177"
                   }
           }
       }';
//        var_dump($data);
        $requestRs = Tool::send($data, "/cgi-bin/message/template/send");
//        var_dump($requestRs);
        $rs = json_decode($requestRs['body'], true);

        if ($rs['errcode'] == 0) {
            return 'ok';
        } else {
//            print_r($rs['errcode']);
//            print_r($rs['errmsg']);
            $message = "";
            if (!empty($rs)) {
                if (isset($rs['errcode'])) {
                    $message .= "errcode:" . $rs['errcode'];
                }
                if (isset($rs['errmsg'])) {
                    $message .= "=====errmsg:" . $rs['errmsg'];
                }
            }
            Tool::mylog(true, __FUNCTION__ . '给客户发送模板错误：', $data . "===" . $message, 'wx_send_tpl_error');
            return 'error';
        }
    }

    /**
     * 获取微信access_token
     * @return type
     */
    public static function wxGetToken()
    {
        $wxtoken = new Wxtoken(Config::get('xpz.app_id'), Config::get('xpz.app_secret'));
        $token = $wxtoken->accessToken();
        return $token;
    }


    public static function send($data, $path)
    {
        $fp = fsockopen('ssl://api.weixin.qq.com', 443, $error, $errstr, 1);
        $http = "POST {$path}?access_token=" . Tool::wxGetToken() . " HTTP/1.1\r\nHost: api.weixin.qq.com\r\nContent-type: application/json\r\nContent-Length: " . strlen($data) . "\r\nConnection:close\r\n\r\n$data\r\n\r\n";
        fwrite($fp, $http);

        $response = '';
        while (!feof($fp)) {
            $response .= fread($fp, 1024);
        }

        if (!$response) {
            return false;
        }

        fclose($fp);

        $separator = '/\r\n\r\n|\n\n|\r\r/';

        list($responseHeader, $responseBody) = preg_split($separator, $response, 2);

        $httpResponse = array(
            'header' => $responseHeader,
            'body' => $responseBody
        );
        return $httpResponse;

    }


    protected static function curl($url, $type = 'get', $post_data = null, $second = 30)
    {
        $ch = curl_init();
        //设置超时
        curl_setopt($ch, CURLOPT_TIMEOUT, $second);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //
        //设置header
        curl_setopt($ch, CURLOPT_HEADER, false);
        //要求结果为字符串且输出到屏幕上
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        if ('post' == $type) {
            curl_setopt($ch, CURLOPT_POST, 1); //开启POST
            curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); //POST数据
        }
        $output = curl_exec($ch);
        curl_close($ch);
        return $output; //返回或者显示结果
    }

    /**
     * 获取客户端浏览器信息
     * @param $agent
     * @return array
     */
    public static function getBrowser($agent)
    {
        $browser = '';
        $browser_ver = '';
        if (preg_match('/OmniWeb\/(v*)([^\s|;]+)/i', $agent, $regs)) {
            $browser = 'OmniWeb';
            $browser_ver = $regs[2];
        }
        if (preg_match('/Netscape([\d]*)\/([^\s]+)/i', $agent, $regs)) {
            $browser = 'Netscape';
            $browser_ver = $regs[2];
        }
        if (preg_match('/safari\/([^\s]+)/i', $agent, $regs)) {
            $browser = 'Safari';
            $browser_ver = $regs[1];
        }
        if (preg_match('/MSIE\s([^\s|;]+)/i', $agent, $regs)) {
            $browser = 'Internet Explorer';
            $browser_ver = $regs[1];
        }
        if (preg_match('/Opera[\s|\/]([^\s]+)/i', $agent, $regs)) {
            $browser = 'Opera';
            $browser_ver = $regs[1];
        }
        if (preg_match('/NetCaptor\s([^\s|;]+)/i', $agent, $regs)) {
            $browser = 'NetCaptor';
            $browser_ver = $regs[1];
        }
        if (preg_match('/Maxthon/i', $agent, $regs)) {
            $browser = 'Maxthon';
            $browser_ver = '';
        }
        if (preg_match('/360SE/i', $agent, $regs)) {
            $browser = '360SE';
            $browser_ver = '';
        }
        if (preg_match('/SE 2.x/i', $agent, $regs)) {
            $browser = '搜狗';
            $browser_ver = '';
        }
        if (preg_match("/OPR\/([\d\.]+)/", $agent, $regs)) {
            $browser = "Opera";
            $browser_ver = $regs[1];
        }
        if (preg_match('/FireFox\/([^\s]+)/i', $agent, $regs)) {
            $browser = 'FireFox';
            $browser_ver = $regs[1];
        }
        if (preg_match('/Lynx\/([^\s]+)/i', $agent, $regs)) {
            $browser = 'Lynx';
            $browser_ver = $regs[1];
        }
        if (preg_match('/Chrome\/([^\s]+)/i', $agent, $regs)) {
            $browser = 'Chrome';
            $browser_ver = $regs[1];
        }
        if ($browser != '') {
            return ['browser' => $browser, 'version' => $browser_ver];
        } else {
            return ['browser' => '未知浏览器', 'version' => ''];
        }
    }

    /**
     * PHP判断当前协议是否为HTTPS
     */
    public static function is_https()
    {
        if (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') {
            return true;
        } elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
            return true;
        } elseif (!empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') {
            return true;
        }
        return false;
    }

    public static function en_token($userId, $companyId)
    {
        return Encrypt::encrypt($userId . "_" . $companyId);
    }

    public static function de_token($token)
    {
        $deToken = Encrypt::decrypt($token);
        if (!empty($deToken)) {
            $tokenArr = explode('_', $deToken);
            if (is_array($tokenArr) && count($tokenArr) == 2) {
                return $tokenArr;
            }
        }
        return [];
    }

    public static function getIdByToken($token)
    {
        $id = 0;
        $deToken = Tool::de_token($token);
        if (!empty($deToken)) {
            $tokenArr = explode('_', $deToken);
            if (is_array($tokenArr) && count($tokenArr) == 2) {
                $id = $tokenArr[0];
            }
        }
        return $id;
    }

    public static function getDomain()
    {
        $protocol = 'http';
        if (self::is_https()) {
            $protocol = 'https';
        }
        return $protocol . "://" . Config::get('xpz.domain');
    }

    /**
     * 加密登录用的token
     * @param type $adminId
     * @param type $userId
     * @param type $openId
     * @return type
     */
    public static function enLoginToken($userId, $openId)
    {
        $expire = time() + Config::get('xpz.login_token_vaild_time');//7天
        return Encrypt::encrypt($userId . "_" . md5($openId) . "_" . $expire);
    }

    /**
     * 解密登录用的token
     * @param type $token
     * @return type
     */
    public static function deLoginToken($token)
    {
        $deToken = Encrypt::decrypt($token);
        if (!empty($deToken)) {
            $tokenArr = explode('_', $deToken);
            if (is_array($tokenArr) && count($tokenArr) == 3) {
                return $tokenArr;
            }
        }
        return [];
    }

    /**
     * [日志log]
     * @param  [type] $mark        [备注]
     * @param  [type] $log_content [内容]
     * @param  string $keyp [名]
     * @return [type]              [description]
     */
    public static function mylog($isEcho, $mark, $log_content, $keyp = "")
    {
        if ($isEcho == 1) {
            $max_size = 30000000;
            if ($keyp == "") {
                $log_filename = RUNTIME_PATH . 'log/' . date('Ym-d') . ".log";
            } else {
                $log_filename = RUNTIME_PATH . 'log/' . $keyp . ".log";
            }

            if (file_exists($log_filename) && (abs(filesize($log_filename)) > $max_size)) {
                rename($log_filename, dirname($log_filename) . DS . date('Ym-d-His') . $keyp . ".log");
            }

            $t = microtime(true);
            $micro = sprintf("%06d", ($t - floor($t)) * 1000000);
            $d = new \DateTime (date('Y-m-d H:i:s.' . $micro, $t));
            if (is_array($log_content)) {
                $log_content = JSONReturn($log_content);
            }
            file_put_contents($log_filename, '   ' . $d->format('Y-m-d H:i:s u') . " key：" . $mark . "\r\n" . $log_content . "\r\n------------------------ --------------------------\r\n", FILE_APPEND);
        }
    }

    public static function get_between($input, $start, $end)
    {

        $b = mb_strpos($input, $start) + mb_strlen($start);
        $e = mb_strpos($input, $end) - $b;
        return mb_substr($input, $b, $e);
    }

    public static function createJsCode($companyId, $token,$kfStyleData, $shareArr=[] )
    {
        $kl = "";
        if (isset($shareArr['douyin']) && !empty($shareArr['douyin'])) {
            $kl .=$shareArr['douyin'] . "@@@";
        }
        if (isset($shareArr['kuaishou']) && !empty($shareArr['kuaishou'])) {
            $kl .=$shareArr['kuaishou'] . "###";
        }
        if (isset($shareArr['taobao']) && !empty($shareArr['taobao'])) {
            $kl .=$shareArr['taobao'] . "###";
        }
        if (isset($shareArr['tianmao']) && !empty($shareArr['tianmao'])) {
            $kl .=$shareArr['tianmao'] . "###";
        }
        if (isset($shareArr['albb']) && !empty($shareArr['albb'])) {
            $kl .=$shareArr['albb'] . "###";
        }

        $domain = Tool::getDomain();
        $jsName = md5($companyId);
//        echo $kl;exit;

        $kfParam = "var xpz_token='" . $token . "';var xpz_domain='" . $domain . "';var xpz_dy='" . $kl . "';var __xpz_kf_color__='" . $kfStyleData['color'] . "';var __xpz_message_display__='" . self::returnKfDisplay($kfStyleData['message_display']) . "';var __xpz_m_popup_display__='" . self::returnKfDisplay($kfStyleData['m_popup_display']) . "';var __xpz_r_popup_display__='" . self::returnKfDisplay($kfStyleData['r_popup_display']) . "';var __xpz_message_title__='" . $kfStyleData['message_title'] . "';var __xpz_m_popup_title1__='" . $kfStyleData['m_popup_title1'] . "';var __xpz_m_popup_title2__='" . $kfStyleData['m_popup_title2'] . "';var __xpz_r_popup_title1__='" . $kfStyleData['r_popup_title1'] . "';var __r_popup_title2__='" . $kfStyleData['r_popup_title2'] . "';";
//        print_r($kfParam);exit;
        $jsAssets = "/assets/chat/js/";

        $jsRootPath = ROOT_PATH . "public/" . $jsAssets;

        $jsContent = file_get_contents($jsRootPath . 'client.js');

        $jsPath = "client/" . $jsName . ".js";

        file_put_contents($jsRootPath . $jsPath, $kfParam . $jsContent);
        return $domain . $jsAssets . $jsPath;
    }

    public static function returnKfDisplay($num)
    {
        if ($num == 1) {
            return "block";
        } else {
            return "none";
        }
    }

}